import Server from '@/config/server';
import request from '@/utils/request';
import { showErrors, showError, showSuccess } from '@/utils/showMsg';

const state = {
  requestCode: false,
  dataLists: [],
  Fields: [],
  itemDetail: {},
  GradeList: [],
};
const actions = {
  // 列表
  getBigScreenLists({ commit }) {
    request.get(Server.action.bigScreen_equipmentMonitor)
      .then((response) => {
        console.log('监控大屏', response);
        if (response.data.errorCode === 0) {
          commit('setLists', response.data.result);
        } else {

        }
      });
  },
  getGroupEquipment({ commit }) {
    request.get(Server.action.bigScreen_groupEquipment).then((response) => {
      console.log(response);
      const data = response.data.result;
      const newData = [];
      if (data.length) {
        data.map((items) => {
          if (items.equipment.length && typeof items.equipment !== 'undefined') {
            items.equipment.map((item) => {
              const obj = {
                company_name: items.company_name,
                equipment_name: `${item.name}`,
                id: item.id,
              };
              newData.push(obj);
            });
          }
        });
      }
      commit('setGradeList', newData);
    });
  },


};
const mutations = {
  setErrorCode(state, text) {
	    state.requestCode = text;
  },
  setLists(state, lists) {
	    state.dataLists = lists;
  },
  setFields(state, lists) {
	    state.Fields = lists;
  },
  setDetail(state, data) {
    state.itemDetail = data;
  },
  setGradeList(state, data) {
    state.GradeList = data;
  },
};
export default {
  namespaced: true,
  state,
  actions,
  mutations,
};
